package com.ygqh.common.okhttp.request;


import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 描述:     封装所有的请求参数到HashMap中
 * 此类是仿照AsyncHttpClient中的请求参数写的
 *
 * @author admin
 */
public class RequestParams {
    /**
     * 线程安全的HashMap
     */
    ConcurrentHashMap<String, String> paramMap = new ConcurrentHashMap<>();

    /**
     * Constructs a new empty {@code RequestParams} instance.
     */
    public RequestParams() {
    }

    /**
     * Constructs a new RequestParams instance containing the key/value string
     * params from the specified map.
     *
     * @param source the source key/value string map to add.
     */
    public RequestParams(Map<String, String> source) {
        if (source != null) {
            for (Map.Entry<String, String> entry : source.entrySet()) {
                put(entry.getKey(), entry.getValue());
            }
        }
    }

    /**
     * Adds a key/value string pair to the request.
     *
     * @param key   the key name for the new param.
     * @param value the value string for the new param.
     */
    public void put(String key, String value) {
        if (key != null && value != null) {
            paramMap.put(key, value);
        }
    }


    public boolean hasParams() {
        return paramMap.size() > 0;
    }

}
